import { about_detail } from "@/api/system"
import { lang } from '@/locales'

function setLocal(key,data){
  localStorage.setItem(key,data)
}
function getLocal(key, defaultVal = 0){
  let data = localStorage.getItem(key)
  return data || defaultVal
}
const state = {
  lang: getLocal('zz_lang', 'zh-cn'),
  index: 0, // 请求的参数
  systemInfo:{},
  qiniu:'',
  isPC: window.screen.width > 768,
  'baseUrl':'http://edu-main.cgteamwork.com/',
  qq: '1076259139',
  serve: 'Timcoco',
  phone:'+8613070165608',
  wx:'hm13070165608',
  channelType: getLocal('zz_channelType', 0)
}

const mutations = {
  SET_Index: (state, index) => {
    state.index = index
  },
  SET_INFO: (state, systemInfo) => {
    state.systemInfo = systemInfo
  },
  SET_QINIU: (state, qiniu) => {
    state.qiniu = qiniu
  },
  SET_SERVE: (state, serve) => {
    state.serve = serve
  },
  SET_QQ: (state, qq) => {
    state.qq = qq
  },
  SET_PHONE: (state, phone) => {
    state.phone = phone
  },
  SET_WX: (state, wx) => {
    state.wx = wx
  },
  SET_CHANNELTYPE: (state, channelType) => {
    state.channelType = channelType
    setLocal('zz_channelType', channelType)
  },
  SET_LANG: (state, lang) => {
    state.lang = lang
    setLocal('zz_lang', lang)
  },
}

const actions = {
  setLang({ commit, state }, data){
    return new Promise((resolve, reject) => {
      const languge = lang[data]?  data : 'zh-cn'
      if(languge != state.lang){
        commit('SET_LANG', languge)
        // location.reload()
      }
      resolve(true)
    })
  },
  setChannelType({ commit }, data){
    return new Promise((resolve, reject) => {
      commit('SET_CHANNELTYPE',data)
      resolve(true)
    })
  },
  setIndex({ commit }, data){
    return new Promise((resolve, reject) => {
      commit('SET_Index',data)
      resolve(true)
    })
  },
  setInfo({commit},data){
    console.log(111111)
    return new Promise((resolve, reject) => {
        commit('SET_INFO', data)
        commit('SET_QINIU', data.qiniu)
        commit('SET_SERVE', data.tg)
        commit('SET_QQ', data.qq)
        commit('SET_PHONE', data.mobile)
        commit('SET_WX', data.wx)
        resolve(true)
      })
    
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
